package com.fan89.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: yongbiao.fan
 * @Date: Create in 2020/8/5 21:29
 * @Url: https://www.fan89.com
 */
@Configuration
@EnableSwagger2
//@ConditionalOnProperty(prefix = "swagger", value = { "enable" }, havingValue = "true")
@EnableSwaggerBootstrapUI
//@ComponentScan("com.fan89.**")
public class SwaggerConfig {
    @Bean
    public Docket getUserDocket(Environment environment){
        Profiles profiles=Profiles.of("dev");
        boolean flag = environment.acceptsProfiles(profiles);

        Contact contact=new Contact("vue小哥","www.baidu,com","2970415515@qq.com");

        ApiInfo apiInfo=new ApiInfoBuilder()
                .title("vueblog接口管理")//api标题
                .description("什么描述")//api描述
                .version("1.0.0")//版本号
                .contact(contact)//本API负责人的联系信息
                .build();

        return new Docket(DocumentationType.SWAGGER_2)//文档类型（swagger2）
                .apiInfo(apiInfo)//设置包含在json ResourceListing响应中的api元信息
                .enable(flag)
                .select()//启动用于api选择的构建器
                .apis(RequestHandlerSelectors.basePackage("com.fan89"))//扫描接口的包
//                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())//路径过滤器（扫描所有路径）
                .build();
    }
}
